class Solution:
    def simplifyPath(self, path: str) -> str:
        pathParts = []
        for pathPart in path.split('/'):
            if not pathPart:
                continue
            if pathPart == '.':
                continue
            if pathPart == '..':
                if pathParts:
                    pathParts.pop()
            else:
                pathParts.append(pathPart)
        if not pathParts:
            return '/'
        result = ''
        for pathPart in pathParts:
            result += '/' + pathPart
        return result
